package com.umanji.usedmarket.domain;

import java.util.Date;
import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.umanji.category.domain.Categories;
import com.umanji.generic.entity.UUIDEntity;
import com.umanji.security.domain.Users;
import com.umanji.user.domain.Members;

@Entity
@Table(name="umanji_used_product")
public class UsedProducts extends UUIDEntity<UsedProducts> {

	@ManyToOne
	@JoinColumn(name="MEMBER_ID", insertable=false, updatable=false)
	private Members member;

    @ManyToOne
    @JoinColumn(name="CATEGORY_ID", insertable=false, updatable=false)
	private Categories category;

	@Column(name = "user_name", nullable = false)
	private String user_name;			// 글 작성자
	
	@Column(name = "product_name", nullable = false)
	private String productName;			// 제품 명

	@Column(name = "product_image", nullable = false)
	private String productImage;		// 제품 이미지

	@Transient
	private CommonsMultipartFile fileData;

	@Column(name = "price", nullable = false)
	private int price;
	
	@Column(name = "contact_info", nullable = false)
	private String contactInfo;			// 연락처 정보

	@Column(name="CONTENTS", length=9000)
	private String content;

	@Generated(GenerationTime.INSERT)
    @Temporal(TemporalType.TIMESTAMP)
	@Column(name = "reg_date", updatable = false, insertable = false)
	private Date regDate = new Date();;

	@Column(name = "count_read", nullable = false)
	private int countRead;

	@Column(name = "latitude", nullable = false)
	private Float lat;

	@Column(name = "longitude", nullable = false)
	private Float lon;

	@Column(name = "product_tag", nullable = false)
	private String productTag;

	@Column(name = "product_tag_etc", nullable = false)
	private String productTagEtc;

	/*
	@Column(insertable = false, updatable = false, nullable=false)
    public UUID getId() {
        return super.getId();
    }

    public void setId(UUID uuid) {
        super.setId(uuid);
    }
    */

	public Members getMember() {
		return member;
	}	
	public void setMember(Members member) {
		this.member = member;
	}
	public Categories getCategory() {
		return category;
	}
	public void setCategory(Categories category) {
		this.category = category;
	}
	public String getContactInfo() {
		return contactInfo;
	}
	public void setContactInfo(String contact_info) {
		this.contactInfo = contact_info;
	}
	public String getProductName() {
		return productName;
	}
	public void setProductName(String product_name) {
		this.productName = product_name;
	}
	public String getProductImage() {
		return productImage;
	}
	public void setProductImage(String product_image) {
		this.productImage = product_image;
	}
	public int getPrice() {
		return price;
	}
	public void setPrice(int price) {
		this.price = price;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public Date getRegDate() {
		return regDate;
	}
	/*
	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}
	*/
	public int getCountRead() {
		return countRead;
	}
	public void setCountRead(int countRead) {
		this.countRead = countRead;
	}
	public Float getLat() {
		return lat;
	}
	public void setLat(Float lat) {
		this.lat = lat;
	}
	public Float getLon() {
		return lon;
	}
	public void setLon(Float lon) {
		this.lon = lon;
	}
	public String getProductTag() {
		return productTag;
	}
	public void setProductTag(String productTag) {
		this.productTag = productTag;
	}
	public String getProductTagEtc() {
		return productTagEtc;
	}
	public void setProductTagEtc(String productTagEtc) {
		this.productTagEtc = productTagEtc;
	}

	public CommonsMultipartFile getFileData()
	{
		return fileData;
	}

	public void setFileData(CommonsMultipartFile fileData)
	{
		this.fileData = fileData;
	}

	@PrePersist
	protected void onCreate() {
		this.regDate = new Date();
	}
	public String getUser_name() {
		return user_name;
	}
	public void setUser_name(String userName) {
		user_name = userName;
	}


}
